#include "Method.h"

double func1(double x){
  return 1.0/x;
}

double dfunc1(double x){
  return -1.0/(x*x);
}

double func2(double x){
  return x*x*x-3*x*x-x+3;
}

double dfunc2(double x){
  return 3*x*x-6*x-1;
}

double func3(double x){
  return sin(x);
}

double dfunc3(double x){
  return cos(x);
}

int main(){
  double (*pf1)(double) = &func1;
  double (*pf2)(double) = &func2;
  double (*pf3)(double) = &func3;
  double (*pdf1)(double) = &dfunc1;
  double (*pdf2)(double) = &dfunc2;
  double (*pdf3)(double) = &dfunc3;
  Secant<double> SC(50,0.01,pf1,pdf1,6,8,0.0001);
  cout << "init0 : " << SC.get_init0() << ", "
       << "init1 : " << SC.get_init1() << endl
       << "max_iter: " << SC.get_max_iter() << ", "
       << "tol: " << SC.get_tol() << ", "
       << "delta : " << SC.get_delta() << endl
       << "f at 2 = " << (*(SC.get_function()))(2) << endl
       << "df at 2 = " << (*(SC.get_dfunction()))(2) << endl;
  SC.set_init0(0.1);
  SC.set_init1(0.15);
  SC.set_max_iter(100);
  SC.set_tol(1e-4);
  SC.set_delta(1e-5);
  SC.set_function(pf3);
  SC.set_dfunction(pdf3);
  cout << "after: " << endl;
   cout << "init0 : " << SC.get_init0() << ", "
       << "init1 : " << SC.get_init1() << endl
       << "max_iter: " << SC.get_max_iter() << ", "
       << "tol: " << SC.get_tol() << ", "
       << "delta : " << SC.get_delta() << endl
       << "f at 2 = " << (*(SC.get_function()))(2) << endl
       << "df at 2 = " << (*(SC.get_dfunction()))(2) << endl;
   cout << "Secant method with initial 0.1 and 0.15:" << endl
        << SC.solve() << endl;
   SC.set_init0(3);
   SC.set_init1(3.1);
   cout << "Newton method with initial 3 and 3.1:" << endl
        << SC.solve() << endl;
  
}
